package com.collect.tanzania.zhiScene.zhiPhoneReview.zhiRoot;

import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.annotation.SuppressLint;
import android.util.Log;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.collect.tanzania.R;
import com.collect.tanzania.zhiBase.BaseActivity;
import com.collect.tanzania.zhiBean.zhiSend.ZHISPhoneReviewFollowEntity;
import com.collect.tanzania.zhiGlobal.zhiAppSettings.ZHIProjectRouter;
import com.collect.tanzania.zhiScene.zhiPhoneReview.zhiFollow.ZHIPhoneReviewFollowFragment;
import com.collect.tanzania.zhiScene.zhiWidget.zhiFilterDaily.ZHIFilterDailyClickListener;
import com.collect.tanzania.zhiScene.zhiWidget.zhiFilterTelemarketing.ZHIFilterTelemaketing;

import butterknife.BindView;

@SuppressLint("NonConstantResourceId")
@Route(path = ZHIProjectRouter.ZHI_ROOT_PHONE_REVIEW)
public class ZHIRootPhoneReviewActivity extends BaseActivity implements ZHIRootPhoneReviewFragmentInterface {

    @BindView(R.id.drawer_layout)
    DrawerLayout drawer_layout;

    @BindView(R.id.drawer_filter_telemarketing)
    ZHIFilterTelemaketing drawer_filter_telemarketing;

    private FragmentManager mFragmentManager;
    private ZHIPhoneReviewFollowFragment mZHIPhoneReviewFollowFragment;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_root_phone_review;
    }

    @Override
    protected void initInjector() {
//        mActivityComponent.inject(this);
    }

    @Override
    protected void initView() {
        try {
            mFragmentManager = getSupportFragmentManager();

            drawer_filter_telemarketing.setZHIFilterDailyClickListener(new ZHIFilterDailyClickListener() {
                @Override
                public void onConfirmClick() {
                    if (drawer_layout.isDrawerOpen(drawer_filter_telemarketing)) {
                        drawer_layout.closeDrawer(drawer_filter_telemarketing);
                    }
                    if (mZHIPhoneReviewFollowFragment != null) {
                        mZHIPhoneReviewFollowFragment.refreshData();
                    }
                }

                @Override
                public void onCloseClick() {
                    if (drawer_layout.isDrawerOpen(drawer_filter_telemarketing)) {
                        drawer_layout.closeDrawer(drawer_filter_telemarketing);
                    }
                }
            });

            selecFragment();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume: ============");
    }

    @Override
    public void onShowFilterFollow() {
//        if (drawer_layout.isDrawerOpen(drawer_filter_telemarketing)) {
//            drawer_layout.closeDrawer(drawer_filter_telemarketing);
//        } else {
//            drawer_layout.openDrawer(drawer_filter_telemarketing);
//        }
    }

    @Override
    public ZHISPhoneReviewFollowEntity onGetFollowFilterParams() {
        return new ZHISPhoneReviewFollowEntity();
    }

    private void selecFragment() {
        FragmentTransaction fragemntTransaction = mFragmentManager.beginTransaction();
        hideFragment(fragemntTransaction);

        if (null == mZHIPhoneReviewFollowFragment) {
            mZHIPhoneReviewFollowFragment = new ZHIPhoneReviewFollowFragment();
            fragemntTransaction.add(R.id.content, mZHIPhoneReviewFollowFragment);
        } else {
            fragemntTransaction.show(mZHIPhoneReviewFollowFragment);
        }

        fragemntTransaction.commitAllowingStateLoss();
    }

    private void hideFragment(FragmentTransaction fragemntTransaction) {
        if (fragemntTransaction == null) return;
        if (null != mZHIPhoneReviewFollowFragment) {
            fragemntTransaction.hide(mZHIPhoneReviewFollowFragment);
        }
    }
}